package com.eunion.web.common.controller;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 全局定义的异常,有用么.
 * 
 * @version 2016年1月18日
 */
//@ControllerAdvice
public class ExceptionGlobalHandler {
    
    private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionGlobalHandler.class);

    @ExceptionHandler(SQLException.class)
    public String handleSQLException(HttpServletRequest request, Exception ex) {
        LOGGER.info("SQLException Occured:: URL=" + request.getRequestURL());
        return "e-exception";
    }

    @ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "IOException occured")
    @ExceptionHandler(IOException.class)
    public void handleIOException() {
        LOGGER.error("IOException handler executed");
        // returning 404 error code
    }
}
